//
//  NewFoodDetailCollectionViewCell.m
//  FoodFamily
//
//  Created by dlios on 15-6-23.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "NewFoodDetailCollectionViewCell.h"

@implementation NewFoodDetailCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =[UIColor whiteColor];
        [self creatSubView];
        
    }
    
    return self;
}


-(void)creatSubView{
   
    
    if (WIDTH < 375) {
        self.scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -35,WIDTH,HEIGHT-20-44-49 +30)];
        self.scrollV.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.scrollV];
        self.scrollV.contentSize = CGSizeMake(0, HEIGHT -110+110);
        [self.scrollV release];
      
    }else if (WIDTH>=375){
        self.scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,WIDTH,HEIGHT-20-44-49 )];
        self.scrollV.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.scrollV];
        self.scrollV.contentSize = CGSizeMake(0, HEIGHT -110);
        [self.scrollV release];

      
    
    }
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, self.frame.size.width-20, self.frame.size.width-20)];
    imageV.image = [UIImage imageNamed:@"bg_share_large@2x.png"];
    [self.scrollV addSubview:imageV];
    [imageV release];
  
    
    
    self.picture_url = [[UIImageView alloc]initWithFrame:CGRectMake(15, 30,WIDTH-30, WIDTH-45)];
    
    self.picture_url.backgroundColor = [UIColor clearColor];
    [self.scrollV addSubview:self.picture_url];
    [self.picture_url release];
    self.picture_url.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
//    [tap setNumberOfTapsRequired: 2];
    [self.picture_url addGestureRecognizer:tap];
    [tap release];
    
   
    
    
    

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10,  WIDTH +5, 200, 10)];
    label.text = @"在这里可以吃到";
    label.font = [UIFont systemFontOfSize:18];
    [self.scrollV addSubview:label];
    
    

    
    UIImageView *imageV1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, WIDTH +18, self.frame.size.width-20, 50)];

    imageV1.backgroundColor = [UIColor clearColor];
    imageV1.image = [UIImage imageNamed:@"bg_share_large@2x.png"];
    [self.scrollV addSubview:imageV1];
    [imageV1 release];
    

      UIImageView *imageV2 = [[UIImageView alloc]initWithFrame:CGRectMake(10, WIDTH +35 , 25, 25)];
    imageV2.image = [UIImage imageNamed:@"address.png"];
    [self.scrollV addSubview:imageV2];
    [imageV2 release];
    

     self.place_name = [[UILabel alloc]initWithFrame:CGRectMake(40, WIDTH +23, self.frame.size.width-20, 27)];
    self.place_name.backgroundColor = [UIColor clearColor];
    self.place_name.font = [UIFont systemFontOfSize:17];
    [self.scrollV addSubview:self.place_name];
    [self.place_name release];
    
    

    self.address = [[UILabel alloc]initWithFrame:CGRectMake(40, WIDTH + 47, self.frame.size.width-20, 18)];

    self.address.font = [UIFont systemFontOfSize:15];
    [self.scrollV addSubview:self.address];
    [self.address release];
    

    
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, WIDTH +75, 200, 10)];
    label1.text = @"评论";
    label1.font = [UIFont systemFontOfSize:18];
    [self.scrollV addSubview:label1];
    
    

    
    UIImageView *imageV3 = [[UIImageView alloc]initWithFrame:CGRectMake(10, WIDTH + 87, WIDTH-20, 70)];
    imageV3.image = [UIImage imageNamed:@"bg_share_large@2x.png"];
    [self.scrollV addSubview:imageV3];
    [imageV3 release];
    
    

    self.user_image = [[UIImageView alloc]initWithFrame:CGRectMake(10,  WIDTH + 90, 40, 40)];
    [self.scrollV addSubview:self.user_image];
    [self.user_image release];
    
    

    self.user_name = [[UILabel alloc]initWithFrame:CGRectMake(55, WIDTH + 90, WIDTH-20, 20)];
    self.user_name.font = [UIFont systemFontOfSize:17];
    self.user_name.textColor = [UIColor redColor];
    [self.scrollV addSubview:self.user_name];
    
    

    self.comment = [[UILabel alloc]initWithFrame:CGRectMake(55, WIDTH +107, WIDTH-55, 50)];
    self.comment.font = [UIFont systemFontOfSize:15];
    [self.scrollV addSubview:self.comment];
    [self.comment setNumberOfLines:0];
    
    
    UIButton *button  = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
//    button.frame = CGRectMake(10, 480, WIDTH-20, 70);
    button.frame = CGRectMake(10, WIDTH + 87, WIDTH-20, 70);

    [self.scrollV addSubview:button];
    
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.comment release];
    
}

-(void)setFoodCM:(FoodCityModle *)foodCM{

    if (_foodCM != foodCM) {
        [_foodCM release];
        _foodCM = [foodCM retain];
    }
    
    NSURL *url = [NSURL URLWithString:self.foodCM.picture_url];
    [self.picture_url sd_setImageWithURL:url];
    
    self.place_name.text = self.foodCM.place_name;
    
    self.address.text = self.foodCM.address;
    
    
    NSURL *url1 = [NSURL URLWithString:self.foodCM.user_image];
    [self.user_image sd_setImageWithURL:url1];
    
    self.user_name.text = self.foodCM.user_name;
    
    if (![self.foodCM.comment isEqualToString:@""]) {
        self.comment.text = self.foodCM.comment;

    }else{
    
    
        self.comment.text = @"味道不错呦!!!";
        
    }
    
    
    


}


//跳转到user页面
-(void)buttonAction{
    
  
    [self.myDelegate bringButton2:self.foodCM.num1];

}






-(void)tapAction{

       [self.myDelegate bringButton];
    
}

-(void)dealloc{
    [_foodCM release];
    [_picture_url release];
    [_place_name release];
    [_address release];
    [_user_image release];
    [_user_name release];
    [_comment release];
    [_scrollV release];
    [super dealloc];
}






@end
